/*-------------------------------------------------------------------------
 *
 * prepare.h
 *	  PREPARE、EXECUTE 和 DEALLOCATE 命令，以及预处理语句存储
 *
 *
 * Copyright (c) 2002-2022, PostgreSQL Global Development Group
 *
 * src/include/commands/prepare.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef PREPARE_H
#define PREPARE_H

#include "commands/explain.h"
#include "datatype/timestamp.h"
#include "utils/plancache.h"

/*
 * 表示预编译语句的数据结构。这现在只是一个简单的封装在计划缓存条目上——主要的
 * 增加是名称的添加。
 *
 * 注意：所有附属存储都存在于引用的计划缓存条目中。
 */
typedef struct
{
	/* dynahash.c 要求键为第一个字段 */
	char		stmt_name[NAMEDATALEN];
	CachedPlanSource *plansource;	/* 实际缓存的计划 */
	bool		from_sql;		/* 通过 SQL 准备，而不是 FE/BE 协议？ */
	TimestampTz prepare_time;	/* stmt被准备的时间 */
} PreparedStatement;


/* 实用语句 PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */
extern void PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
						 int stmt_location, int stmt_len);
extern void ExecuteQuery(ParseState *pstate,
						 ExecuteStmt *stmt, IntoClause *intoClause,
						 ParamListInfo params,
						 DestReceiver *dest, QueryCompletion *qc);
extern void DeallocateQuery(DeallocateStmt *stmt);
extern void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into,
								ExplainState *es, const char *queryString,
								ParamListInfo params, QueryEnvironment *queryEnv);

/* 对存储的准备语句的低级访问 */
extern void StorePreparedStatement(const char *stmt_name,
								   CachedPlanSource *plansource,
								   bool from_sql);
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
												 bool throwError);
extern void DropPreparedStatement(const char *stmt_name, bool showError);
extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt);
extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt);

extern void DropAllPreparedStatements(void);

#endif							/* PREPARE_H */
